package pe.edu.upc.dsd.ws;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Servlet implementation class ServletJmsRequest
 */
public class ServletJmsRequest extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
           
        } finally { 
            out.close();
        }
    } 
   

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
			
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		
		 String experiencia=request.getParameter("txtExperiencia");
		 String mensaje="";
		 final Logger logger=Logger.getLogger(ServletJmsRequest.class);
		 
		 MessageProducer messageProducer;
		 ApplicationContext context = new ClassPathXmlApplicationContext("/applicationContext.xml");
		 messageProducer=context.getBean("queueMessageProducer",MessageProducer.class);
		 
		 try{
				messageProducer.send(experiencia);
				mensaje="Inserto Curriculum a la cola";
				logger.debug(mensaje);
				
			}catch (Exception e) {
				mensaje="Error en el servidor";
				e.printStackTrace();
			}
		request.setAttribute("mensaje",mensaje);
		
		 request.getRequestDispatcher("Curriculum.jsp").forward(request, response);
	}

}
